/**
 * Created by zhongwenwen on 2017/9/2.
 */
define(["jquery","template","bootstrap"],function($,template){

    //页面加载请求列表数据
    $.ajax({
        url:"/api/teacher",
        type:"get",
        success: function(info){
            if(info.code==200){
                var html = template("teacherListTpl",info);
                $("#teacherTable>tbody").html(html);
            }
        }
    })

   //自定义过滤器
    template.defaults.imports.dateFmt = function(input){
        return input.split("|").join(" ");
    }
   //查看讲师请求数据
    $("#teacherTable").on("click",".look",function(){
        var infoId = $(this).parent("td").attr("data-info-id");
        $.ajax({
            url:"/api/teacher/view",
            type: "get",
            data: {tc_id:infoId},
            success:function(info){
                if(info.code==200){
                    //console.log(info.result);
                    var html = template("teacherInfo",info.result);
                    $(".panel-body>.table").html(html);
                }
            }
        })
        $("#teacherModal").modal("show");
    })

    var status = ["启用","注销"];
    $("#teacherTable").on("click",".outLine",function(){
        var infoId = $(this).parent("td").attr("data-info-id");
        var infoStatus = $(this).attr("data-info-status");
        var that = this;
        $.ajax({
            url: "/api/teacher/handle",
            type: "post",
            data: {tc_id: infoId,tc_status: infoStatus},
            success:function(info){
                if(info.code==200){
                   $( that ).attr( 'data-info-status', info.result.tc_status).
                       text(status[info.result.tc_status]);
               }
            }
        })
        return false;
    })
})